(function() {

	var leo = {
		//更改兴趣模块
		'changeInterrst':function(){
			var interrstBtn = document.getElementsByClassName('interest-r')[0]
			var mask = document.getElementsByClassName('mask')[0]
			var alertNode = document.getElementsByClassName('alertNode')[0]
			var alertNodeUlAllLi = document.getElementsByClassName('alertNode-ul')[0].children
			var alUl = document.getElementsByClassName('alertNode-CONTECT')[0].children
			var allLi = document.getElementsByClassName('alertNode-CONTECT')[0].getElementsByTagName('li')
		var	alertNodeOl = document.getElementsByClassName('alertNode-ol')[0]
		allNumber
		
			for(var i =0;i<alertNodeUlAllLi.length;i++){
				alertNodeUlAllLi[i].index =i
				alertNodeUlAllLi[i].onclick = function(){
					for(var j = 0;j<alertNodeUlAllLi.length;j++){
						alertNodeUlAllLi[j].className = ''
						alUl[j].className = ''
						
						
					}
					alertNodeUlAllLi[alertNodeUlAllLi.length-1].className = 'no'
					this.className += ' active'
					alUl[this.index].className ='show'
				}
			}
			alertNodeOl.onclick =function(){
				if(event.target.nodeName == 'IMG'){
					for(var i=0;i<allLi.length;i++){
						if(allLi[i].innerText ==event.target.parentNode.title){
						allLi[i].className = ''	 ;
						break;
						}
						
					}
					alertNodeOl.removeChild(event.target.parentNode)
					allNumber.innerText = alertNodeOl.children.length-1
					alertNode.style.marginTop = -alertNode.offsetHeight/2+'px'
				}
			}
			for(var i =0;i<allLi.length;i++){
				allLi[i].onclick = function(){
					if(this.className == 'active'){
						this.className =''
						for(var i=0;i<alertNodeUlAllLi.length;i++){
							if(this.innerText==alertNodeOl.children[i].title ){
								alertNodeOl.removeChild(alertNodeOl.children[i])
								break
							}
						}
					}
					else{
						this.className = 'active'
						var oli = document.createElement('li')
						oli.title = this.innerText
						oli.innerHTML = this.innerText +`<img src="img/colosd.gif" />`
						alertNodeOl.appendChild(oli)
					}
					allNumber.innerText = alertNodeOl.children.length-1
					alertNode.style.marginTop = -alertNode.offsetHeight/2+'px'
				}
				allLi[i].onmousedown = function(){
									return false;
								};
				
			}
			mask.style.opacity = 0
			alertNode.style.opacity =0
			mask.style.transition ='0.5s'
			alertNode.style.transition = '0.5s'
			interrstBtn.onclick = function(){
				mask.style.display = 'block'
				alertNode.style.display = 'block'
				setTimeout(()=>{
					mask.style.opacity = 1
					alertNode.style.opacity =1
				},0)
				setTimeout(()=>{
					mask.style.transition = '0s'
					alertNode.style.transition ='0s'
				},200)
				
			}
			chouse.onclick =function(){
				alertNode.style.transition = '0.7s'
				mask.style.transition = '0.7s'
				  setTimeout(()=>{
					alertNode.style.opacity = '0'
					mask.style.opacity = '0'
				
				},0)
				setTimeout(()=>{
					alertNode.style.display = 'none'
					mask.style.display = 'none'
				
				},500)
			}
			alertNodeClosed.onclick = function(){
				alertNode.style.transition = '0.7s'
				mask.style.transition = '0.7s'
				  setTimeout(()=>{
					alertNode.style.opacity = '0'
					mask.style.opacity = '0'
				
				},0)
				setTimeout(()=>{
					alertNode.style.display = 'none'
					mask.style.display = 'none'
				
				},500)
				
			}
		},
		
		//限时秒杀模块
		'timebuy' :function(){
			var seckillTabTop = document.getElementsByClassName('seckill-tab-top')[0]
			var  allLi = seckillTabTop.children;
		var seckillTabContent = document.getElementsByClassName('seckill-tab-content')[0]
		var allUl = seckillTabContent.children
			for(var i=0;i<allLi.length;i++){
				allLi[i].index =i
				allLi[i].onmouseover = function(){
				for(var j=0;j<allLi.length;j++){
					allLi[j].className = ''
					// allUl[j].style.display ='none'
				}
				allLi[0].className = 'first'
				allLi[allLi.length-1].className = 'no'
				this.className +=' active'	
				allUl[this.index].style.display ='block'
				}
				
			}
		},
		//滚动事件
		"windowScroll":function(){
			var topNode = document.getElementsByClassName('topNode')[0]
			var topNodeCopy = document.getElementsByClassName('topNode-copy')[0]
			var windowShow = document.getElementsByClassName('window-show')[0]
			var showT = document.getElementsByClassName('show-t')[0]
		var	timer = null
			window.onscroll = function(){
				if(document.documentElement.scrollTop>1){
					windowShow.style.display ='block'
				}
				else{
					windowShow.style.display ='none'
				}
				if(document.documentElement.scrollTop>=550){
					topNode.style.position = 'fixed';
					topNodeCopy.style.display = 'block'
				}
				else{
					topNode.style.position = 'relative';
					topNodeCopy.style.display = 'none'
				}
			}
			//点击回到顶部
			showT.onclick = function(){
				clearInterval(timer)
				timer = setInterval(()=>{
					if(document.documentElement.scrollTop <=0){
						clearInterval(timer)
						return
					}
					document.documentElement.scrollTop = document.documentElement.scrollTop-30 <0 ? 0: document.documentElement.scrollTop-30
				},0)
			}
		},
		//下载按钮触碰事件
		'downTouch' :function(){
			var downAppButton  = document.getElementsByClassName('downApp')[0]
			var downShow  = document.getElementsByClassName('downloadApp-show')[0]
			var timer = null
			downAppButton.onmouseover = function(){
				clearTimeout(timer)
				if(downShow.style.display =='block') return
				downShow.style.display = 'block'
				downShow.style.transform = 'scale(0.9)'
				timer = setTimeout(()=>{
					downShow.style.transform = 'scale(1)'
				},0)
			}
			downAppButton.onmouseout = function(){
			clearTimeout(timer)
				timer = setTimeout(()=>{
				
						downShow.style.display ='none'
				},100)
			}
			downShow.onmouseout = function(){
				clearTimeout(timer)
					timer = setTimeout(()=>{
					
							downShow.style.display ='none'
					},100)
					
			}
			downShow.onmouseover =function(){
				clearTimeout(timer)
			}
			
		},
		// 我的学习触碰事件
		'myTouchu':function(){
		var myButton  = document.getElementsByClassName('bannerTop-my')[0]
		var myContent  = document.getElementsByClassName('bannerTop-my-content')[0]
		var timer = null
		myButton.onmouseover = function(){
			clearTimeout(timer)
			if(myContent.style.display =='block') return;
			myContent.style.display ='block'
			myContent.style.transform ='scale(0.9)'
			myContent.style.transition = '0.17s';
			setTimeout(()=>{
				myContent.style.transform = 'scale(1)'
			},0)
		}
		myButton.onmouseout = function(){
			clearTimeout(timer)
		timer =	setTimeout(()=>{
			myContent.style.display = 'none'
			},300)
		}
		myContent.onmouseout = function(){
			clearTimeout(timer)
			timer = setTimeout(()=>{
				myContent.style.display = 'none'
			},300)
		}
		
		myContent.onmouseover = function(){
			clearTimeout(timer)
		}
		},
		//用户头像触碰事件
		'userImageTouch': function() {
			var usrImage = document.getElementsByClassName('user-image')[0]
			var userUl = document.getElementsByClassName('user-ul')[0]
			var myContent  = document.getElementsByClassName('bannerTop-my-content')[0]
			
			var timer = null
			usrImage.onmouseover = function() {
				myContent.style.display='none'
					clearTimeout(timer)
					if(userUl.style.display == 'block')
					{
						return
					}
				userUl.style.display = 'block'
				userUl.style.transition = '0.3s'
				userUl.style.transform = 'scale(0.9)'
				setTimeout(function(){
					userUl.style.transform  = 'scale(1)'
				},0)
			}
			usrImage.onmouseout = function() {
				clearTimeout(timer)
				timer = setTimeout(function() {
					userUl.style.display = 'none'

				}, 200)

			}
			userUl.onmouseover =function(){
					clearTimeout(timer)
			}
			userUl.onmouseout = function(){
				clearTimeout(timer)
				timer = setTimeout(function() {
					userUl.style.display = 'none'
				
				}, 200)
			}
		},
		//搜索框事件
		'searchEvent': function() {
			var searchLeftChangeButton = document.getElementsByClassName('searchNodeLeft')[0]
			var searchleftUL = document.getElementsByClassName('searchNodeLeft-ul')[0]
			var searchleftULAllNode = searchleftUL.children;
			var searchShowOl = document.getElementsByClassName('searchNode-ol')[0]
			var searchInput = document.getElementsByClassName('searchNodeInput')[0]
			var searchNodeLeftText = document.getElementsByClassName('searchNodeLeftText')[0]
			var searchShowOlAllNode = searchShowOl.children
			var content = {
				'k': ['摄影', '产品可视化', 'Ai必学-Tensorflow', '产品经理', 'AE'],
				'w': ['城市', '滨州学院', '54', 'edufancy', '北京理工大学']
			}


			window.onclick = function() {
				searchShowOl.style.display = 'none'
			}

			searchLeftChangeButton.onmouseover = function() {
				if (event.target.nodeName == 'DIV' || event.target.nodeName == "SPAN") {
					searchLeftChangeButton.className = 'searchNodeLeft active'

				} else {
					searchLeftChangeButton.className = 'searchNodeLeft'
				}
			}
			ToOlContent('k')

			function ToOlContent(text) {
				console.log(searchShowOlAllNode)
				searchShowOl.innerHTML = `<li class="first">热门搜索</li>`;
				searchShowOlAllNode[0].onclick = function() {
					event.cancelBubble = true
				}
				for (var i = 0; i < content[text].length; i++) {
					var Oli = document.createElement('li');
					Oli.innerHTML = `<a href ='#' > ${content[text][i]}</a>`
					searchShowOl.appendChild(Oli)
				}


				for (var i = 1; i < searchShowOlAllNode.length; i++) {
					searchShowOlAllNode[i].onclick = function() {
						event.bubbles = true
						searchShowOl.style.display = 'none'
					}
				}
			}

			for (var i = 0; i < searchleftULAllNode.length; i++) {
				searchleftULAllNode[i].onclick = function() {
					event.cancelBubble = true
					for (var i = 0; i < searchleftULAllNode.length; i++) {
						searchleftULAllNode[i].className = ''
					}
					this.className = 'active'
					searchNodeLeftText.innerHTML = this.innerHTML
					searchleftUL.style.display = 'none'
					Olshow()
					if (this.innerHTML == '网校') {
						ToOlContent('w')
						searchInput.placeholder = '搜索网校'
					} else {
						searchInput.placeholder = '零基础学习java'
						ToOlContent('k')
					}

				}
			}

			var Olshow = function() {
				searchShowOl.style.transition = '0.7s'

				searchShowOl.style.opacity = '0'
				searchShowOl.style.display = 'block'
				setTimeout(function() {
					searchShowOl.style.opacity = '1'
				}, 0)
			}
			// searchInput.onfocus  = Olshow
			searchInput.onclick = function() {
				event.cancelBubble = true
				Olshow()
			}

			searchLeftChangeButton.onmouseenter = function() {

				searchleftUL.style.display = 'block'
				searchShowOl.style.display = 'none'
			}
			searchLeftChangeButton.onmouseout = function() {
				searchLeftChangeButton.className = 'searchNodeLeft'
			}
			searchLeftChangeButton.onmouseleave = function() {

				searchleftUL.style.display = 'none'
			}
		},

		//公开课移动事件
		'openShow': function() {
			var leftBtn = document.getElementsByClassName('card-left')[0];
			var rightBtn = document.getElementsByClassName('card-right')[0];
			var openUl = document.getElementsByClassName('open-content-card')[0];
			rightBtn.style.display = 'none';
			leftBtn.onclick = function() {
				this.style.display = 'none';
				rightBtn.style.display = 'block';
				openUl.style.left = '-368px';
			}
			rightBtn.onclick = function() {
				this.style.display = 'none';
				leftBtn.style.display = 'block';
				openUl.style.left = '10px';
			}
		},


		//banner 二级菜单
		"bannerShow": function() {
			// "bannerShow": function(){
			var allLi = document.getElementsByClassName('banner-a');
			var allshowOl = document.getElementsByClassName('active-ol');
			var rightOl = document.getElementsByClassName('right-ol')[0];
			for (var i = 0; i < allLi.length; i++) {
				allLi[i].onmouseover = function() {
					for (var i = 0; i < allshowOl.length; i++) {
						allshowOl[i].style.display = "none";


					}
					if (this.parentNode.getElementsByClassName('active-ol')[0]) {
						this.parentNode.getElementsByClassName('active-ol')[0].style.display = "block";

					}

				}
			}
			topBanner.onmouseleave = function() {
				for (var i = 0; i < allshowOl.length; i++) {
					allshowOl[i].style.display = "none";

				}
			}
			rightOl.onmouseenter = function() {
				for (var i = 0; i < allshowOl.length; i++) {
					allshowOl[i].style.display = "none";

				}
				alert(4)
			}

		},
		"slider": function() {

			var num = 0;
			var setInterSilder = null;
			var timer = null;
			var allSilderButton = document.getElementsByClassName('silder-content-button')[0];
			var allSliderContent = document.getElementsByClassName('silder-content-ULNode')[0].children;
			var allli = allSilderButton.children;
			var silderContentNode = document.getElementsByClassName('silder-content')[0];
			var colorArr = ['#f15c5a', '#f5a52c', '#f9a916', '#f64b3a', '#283042', '#0096ee', '#2b409b'];
			for (var i = 0; i < allli.length; i++) {

				allli[i].index = i;
				allli[i].onmouseover = function() {
					clearInterval(timer);
					timer = setTimeout(function() {
						move(this);
						go();
					}.bind(this), 500);


				}
			}

			function move(_this) {
				num = _this.index;
				for (var i = 0; i < allli.length; i++) {
					allSliderContent[i].className = "";
					allSliderContent[i].style.opacity = 0;
					if (allli[i].className.indexOf('first') != -1) {
						allli[i].className = 'first';
					} else {
						allli[i].className = "";
					}

				}

				allSliderContent[_this.index].className = 'active';
				setTimeout(function() {
					allSliderContent[this.index].style.opacity = '1';

				}.bind(_this), 1);
				silderContentNode.style.backgroundColor = colorArr[_this.index];
				this.className += " active";

			}
			go();

			function go() {
				clearInterval(setInterSilder);
				setInterSilder = setInterval(function() {
					num++;
					if (num == allli.length) num = 0;

					for (var i = 0; i < allli.length; i++) {
						allSliderContent[i].className = "";
						allSliderContent[i].style.opacity = 0;
						if (allli[i].className.indexOf('first') != -1) {
							allli[i].className = 'first';
						} else {
							allli[i].className = "";
						}

					}

					allSliderContent[num].className = 'active';
					setTimeout(function() {
						allSliderContent[num].style.opacity = '1';

					}, 0);
					allli[num].className += " active";
					silderContentNode.style.backgroundColor = colorArr[num];

				}, 3000);
			}


		}
	}
	leo.windowScroll()
	leo.slider();
	leo.bannerShow();
	leo.openShow();
	leo.searchEvent();
	//用户头像点击事件
	leo.userImageTouch();
	leo.myTouchu();
	leo.downTouch()
	//限时秒杀
	leo.timebuy()
	leo.changeInterrst()
})();